package br.com.etecmatao.business.impl;

import br.com.etecmatao.business.AbstractBusiness;
import br.com.etecmatao.business.LoginBusiness;
import br.com.etecmatao.business.exception.BusinessValidateException;
import br.com.etecmatao.model.Login;

public class LoginBusinessImpl extends AbstractBusiness implements LoginBusiness {

    @Override
    public Login logar(Login login) throws BusinessValidateException {
        try {
            Login loginBD = daoFactoryLocator.getLoginDAO().findById(login.getEmail());
            if (loginBD != null && loginBD.getSenha().equals(login.getSenha())) {
                return loginBD;
            }
        } catch (Exception e) {
            throw new BusinessValidateException("Login.invalid");
        }

        return null;
    }

    public void save(Login login) {
        Login l = daoFactoryLocator.getLoginDAO().save(login);
    }

    public void delete(Login login) {
        daoFactoryLocator.getLoginDAO().delete(login);
    }

    public void update(Login login) {
        daoFactoryLocator.getLoginDAO().update(login);
    }
}
